//    Copyright (C) Kherty.  All rights reserved.
namespace OpenLS.Spreadsheet.Extensibility
{
    public class AllowPercentToDoubleConverter : ParameterConverterAttribute
    {

        internal override void ConvertImp(ConversionData data)
        {
            if (data.Value is string && data.TargetType== typeof(double))
            {
                string s = (string)data.Value;
                s = s.Trim();
                if (s.EndsWith("%") && s.Length > 1)
                {
                    s = s.Substring(0, s.Length - 1);
                    double v;
                    if (double.TryParse(s, out v))
                    {
                        data.Result = v / 100;
                    }
                }

            }

        }
    }
}
